//
// Created by haoy on 2017/6/20.
//

#include "rtp/rtp_factory.hpp"

std::shared_ptr<RtpPacket> RtpFactory::read(const uint8_t *data, const int size,
                                                  rtc_codecs_t* codecs) {
    auto packet = allocate();
    auto packet_size = packet->read(data, size, codecs);
    if (packet_size == 0) {
        return nullptr;
    }
    return packet;
}

std::shared_ptr<RtpPacket> RtpFactory::allocate() {
    for (auto& p : packets_) {
        if (p.use_count() == 1) {
            return p;
        }
    }
    auto p = std::make_shared<RtpPacket>();
    packets_.emplace_back(p);
    return p;
};